<style>
    .form-copy {
        margin-right: 5px;
        border-radius: 0;
        box-shadow: none;
        padding: 4px 12px 7px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #555;
        border: 1px solid #ccc;
        transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    }
    .select2 {
        margin-right: 5px
    }
</style>
<div class="btn-group" style="margin-right: 10px">
    <form action="{{ $action }}" pjax-container method="get">
        <input style="width: 110px" type="text" id="reportFromDate" name="reportFromDate" value="{{ $filtersBlade['reportFromDate'] }}" class="form-copy" placeholder="开始日期">
        <input style="width: 110px" type="text" id="reportEndDate" name="reportEndDate" value="{{ $filtersBlade['reportEndDate'] }}" class="form-copy" placeholder="截止日期">
        <input type="text" class="form-copy" style=" width:150px;" name="taskId" value="{{ $filtersBlade['taskId'] }}" placeholder="TaskId">
        <input type="text" class="form-copy" style=" width:150px;" name="rpaId" value="{{ $filtersBlade['rpaId'] }}" placeholder="RpaId">
        <input type="text" class="form-copy" style=" width:150px;" name="storeName" value="{{ $filtersBlade['storeName'] }}" placeholder="店铺名称">
        <input type="text" class="form-copy" style=" width:150px;" name="siteCode" value="{{ $filtersBlade['siteCode'] }}" placeholder="站点名称">
        <select id="status" name="status">
            {{ $filtersBlade['status'] }}
        </select>
        <button class="btn btn-sm btn-info submit"><i class="fa fa-search"></i>&nbsp;&nbsp;{{ trans('admin.search') }}</button>
        <a style="margin-left: 10px;" href="{{ $action }}" class="btn btn-sm btn-default"><i class="fa fa-undo"></i>&nbsp;&nbsp;{{ trans('admin.reset') }}</a>
    </form>
    <div style="margin-top: 10px;">
        <button class="btn btn-sm btn-twitter tasks-results"><i class="fa fa-retweet"></i>&nbsp;<span id="loading-tasks-results">获取结果</span></button>
    </div>
</div>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('#reportFromDate').datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","allowInputToggle":true});
        $('#reportEndDate').datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","maxDate":moment(),"allowInputToggle":true});
        $('#status').select2({placeholder: '状态', allowClear: true, width: '100px'});

        $('.tasks-results').unbind('click').click(function(e) {
            e.preventDefault();
            swal({
                title: "确定？",
                text : "确定获取结果吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        $.ajax({
                            method: 'post',
                            url: '/xqc/ziniao/tasks-results-ajax',
                            data: {
                                _token:"{{ csrf_token() }}",
                                action:"tasksResults"
                            },
                            beforeSend: function(){
                                $('#loading-tasks-results').text('获取中');
                                $(this).attr('disabled',true);
                            },
                            success: function (data) {
                                resolve(data);
                            }
                        });
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    $('#loading-tasks-results').text('获取结果');
                    $(this).removeAttr('disabled');
                    if (data.status) {
                        $.pjax.reload('#pjax-container');
                        toastr.success('操作成功 !');
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });
    });
</script>
